package keshe;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import org.jetbrains.annotations.NotNull;
import redis.clients.jedis.Jedis;


import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
//登录界面
public class Login extends JFrame implements ActionListener{
    JButton b1=new JButton("登录");
    JButton b2=new JButton("退出");
    JLabel la1=new JLabel("用户名");
    JLabel la2=new JLabel("密码");
    JPanel p1=new JPanel();
    JPanel p2=new JPanel();
    JPanel p3=new JPanel();
    Jedis jedis= new Jedis("127.0.0.1",6379);
    JTextField name=new JTextField(15);
    JPasswordField pw=new JPasswordField(15);
    public Login(){
        setTitle("学生成绩管理系统");
        getContentPane().setLayout(new GridLayout(3,1));
        getContentPane().add(p1);
        getContentPane().add(p2);
        getContentPane().add(p3);
        p1.add(la1);
        p1.add(name);
        p2.add(la2);
        p2.add(pw);
        p3.add(b1);
        p3.add(b2);
        setBounds(500, 250, 100, 100);
        pack();
        setVisible(true);
        pw.setEchoChar('*');
        b1.addActionListener(this);
        b2.addActionListener(this);
    }


    public void actionPerformed(@NotNull ActionEvent e) {


        jedis.set("user","fjx");
        jedis.set("password","123456");
        if(e.getActionCommand()=="登录"){

            String password=pw.getText();
            String user=name.getText();

            if(user.equals(jedis.get("user"))&&password.equals(jedis.get("password"))){
                Function function=new Function();
                function.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setVisible(false);
            }
            else{
                JOptionPane.showMessageDialog(null, "用户名或密码错误", "Error", JOptionPane.INFORMATION_MESSAGE);
            }
        }
        else if(e.getActionCommand()=="退出"){
            System.exit(0);
        }
    }

}
